///**
// * author      : dormi330
// * date        : 2018/6/27
// * project     : mybatis
// * description : 支付一个已经存在的订单
// */
//
//package org.wzq.learn.domain.order;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Isolation;
//import org.springframework.transaction.annotation.Propagation;
//import org.springframework.transaction.annotation.Transactional;
//import org.wzq.learn.adaptor.PayService;
//
//import java.math.BigDecimal;
//import java.util.List;
//
//@Service
//public class CommandPayOrder {
//
//    private Logger logger = LoggerFactory.getLogger(this.getClass().getName());
//
//    @Autowired
//    private PayService payService;
//
//    @Autowired
//    private OrderQueryRepository orderQueryRepository;
//
//    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
//    public void payOrder(OrderSummary orderSummary, String payChannel) throws Exception {
//        if (null == orderSummary) {
//            throw new Exception("payOrder, argument cannot be null");
//        }
//
//        if (isOrderCanPay(orderSummary)) {
//            throw new Exception("payOrder, the order cannot be paid, orderSummaryId=" + orderSummary.getId());
//        }
//
//        try {
//            doPay(orderSummary.getPayMoney(), orderSummary.getId(), payChannel);
//            // 直接模拟 支付成功
//            afterOrderPaid(orderSummary);
//        } catch (Exception ex) {
//            // TODO logger
//        }
//    }
//
//    private boolean isOrderCanPay(OrderSummary orderSummary) {
//        String tenantCode = orderSummary.getTenantCode();
//        String orderSummaryId = orderSummary.getId();
//
//        List<TradeOrder> tradeOrderList = orderQueryRepository.tradeOderOfOrderSummary(tenantCode, orderSummaryId);
//        boolean canPay = (
//                null != orderSummary.getPayTime()
//                && orderSummary.getPayMoney().compareTo(BigDecimal.ZERO) == 1
//        );
//        return canPay;
//    }
//
//    // 进行支付, 实际支付待定
//    private void doPay(BigDecimal money, String orderNo, String payChannel) {
//        payService.pay(money, orderNo, payChannel);
//    }
//
//    /**
//     * 正常情况下, mq消息订阅, 触发这个方法的调用
//     * 订单支付成功后的动作
//     */
//    public void afterOrderPaid(OrderSummary orderSummary) {
//
//    }
//
//}
